import { PickType } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import {
    ArrayNotEmpty,
    IsArray, IsNotEmpty, IsNumber,
    IsOptional,
    IsString,
    ValidateNested
} from 'class-validator';

export type gateinCntrFeedet = {
    fee_unit_cod: number;
    fee_in_out: string;
    fee_cod: string;
    currency_cod: string;
    amount: number;
};

export class PlanDto {
    @IsNotEmpty({
        message: '计划名称不能为空',
    })
    plan_name: string;

    /* @IsNotEmpty({
        message: '计划日期不能为空',
    }) */
    plan_date: Date;

    /* e_f_id: string; 
    plan_kind: string;*/
    @IsNotEmpty({
        message: '作业目的不能为空',
    })
    stat_cod: string;

    /* @IsNotEmpty({
        message: '计划类型不能为空',
    }) */
    carry_id: string;

    /* @IsNotEmpty({
        message: '箱况不能为空',
    }) */
    dam_id: string;

    @IsNotEmpty({
        message: '箱尺寸不能为空',
    })
    cntr_siz_cod: string;

    @IsNotEmpty({
        message: '箱型不能为空',
    })
    cntr_typ_cod: string;
    @IsNotEmpty({
        message: '站点不能为空',
    })
    cfs_cod: number;
    @IsNotEmpty({
        message: '成本中心不能为空',
    })
    cntr_owner: number;

    lock_id: string;
    @IsNotEmpty({
        message: '箱量不能为空',
    })
    cntr_num: number;

    bill_no: string;
    // cntr_work_num?: number;
    // from_plac: number;
    // to_pla: number;
    // trade_id: string;
    // spec_no: string;
    finish_id: string;
    need_email: string;
    /* @IsArray({
        each: true,
        message: '计划费用参数错误'
    }) */
    @IsArray()
    @ValidateNested({ each: true }) // 对数组中的每个元素应用验证
    @Type(() => PlanFeedetDto) // 使用class-transformer确保类型安全
    @IsOptional()
    fees: PlanFeedetDto[];

    remark: string;
}

export class InPlanDto extends PlanDto {
    @IsNotEmpty({
        message: '供应商不能为空',
    })
    cntr_oper_cod: number;

    in_reason: string;
    // free_days: number;

}

export class OutPlanDto extends PlanDto {
    @IsNotEmpty({
        message: '客户不能为空',
    })
    cntr_corp_cod: number;
    free_days: number;
    currency_cod: string;

}

export class LeasePlanDto extends PickType(OutPlanDto, ['carry_id', 'bill_no', 'cfs_cod', 'cntr_num', 'cntr_owner'
    ,'cntr_siz_cod', 'cntr_typ_cod', 'dam_id', 'fees', 'finish_id', 'plan_date', 'plan_name', 'cntr_corp_cod'
]) {
    free_days: number;
}
export class RentPlanDto extends PickType(InPlanDto, ['carry_id', 'plan_name', 'plan_date', 'cntr_num', 'cntr_owner',
    'cntr_siz_cod', 'cntr_typ_cod', 'finish_id', 'fees'
]) {}
export class PlanFeedetDto {
    @IsOptional()
    truck_sn: number;

    fee_owner: number;

    @IsNotEmpty({
        message: '客户不能为空',
    })
    fee_unit_cod: number;

    @IsNotEmpty({
        message: '收付类型不能为空',
    })
    fee_in_out: string;

    @IsNotEmpty({
        message: '费用类型不能为空',
    })
    fee_typ_cod: string;
    
    @IsNotEmpty({
        message: '费目不能为空',
    })
    fee_cod: string;

    @IsNotEmpty({
        message: '货币不能为空',
    })
    currency_cod: string;

    fee_pay_kind: string;

    @IsNotEmpty({
        message: '金额不能为空',
    })
    amount: number;
}

export class PlanCntrDto {
    @IsOptional()
    truck_sn: number;

    @IsNotEmpty({
        message: '箱号不能为空',
    })
    cntr: string;

    @IsOptional()
    cntr_no: number;

    remark: string; 
}
export class CreateCntrDto {
    @IsNotEmpty({
        message: '箱号不能为空',
    })
    cntr: string;

    /* @IsNotEmpty({
        message: '空重不能为空'
    })
    e_f_id: string; */

    /* @IsNotEmpty({
        message: '进场箱况不能为空',
    })
    in_dam_id: string; */

    @IsNotEmpty({
        message: '箱况不能为空',
    })
    dam_id: string;

    @IsNotEmpty({
        message: '箱尺寸不能为空',
    })
    cntr_siz_cod: string;

    @IsNotEmpty({
        message: '箱型不能为空',
    })
    cntr_typ_cod: string;

    @IsNumber({}, {
        message: '供应商错误',
    })
    @IsOptional()
    cntr_oper_cod: number;

    @IsNumber({}, {
        message: '客户错误',
    })
    @IsOptional()
    cntr_corp_cod: number;

    cntr_net_wgt: number;
    
    @IsNumber({}, {
        message: '进场计划号错误',
    })
    @IsNotEmpty({
        message: '进场计划号不能为空'
    })
    in_truck_sn: number;

    /*from_plac: number;

    cy_area_no: string;
    cy_bay_no: string;
    cy_row_no: string;
    cy_tier_no: string;

    cntr_create_kind: string;
    trade_id: string; */
    
    @IsNumber({},{
        message: '站点错误'
    })
    @IsNotEmpty({
        message: '站点不能为空'
    })
    cfs_cod: number;

    /* @IsNotEmpty({
        message: '收箱提单号不能为空',
    }) */    
    bill_no: string;

    /* @IsDate({
        message: '进场时间错误'
    }) */
    @IsNotEmpty({
        message: '进场时间不能为空'
    })
    to_port_tim: Date;
    out_truck_no_c: string;
    out_truck_tel: string;
    /* in_truck_no_c: string;
 */
    current_stat: string;
/*     last_cntr_stat: string;
    last_stat_tim: Date;
 */
    @IsNotEmpty({
        message: '箱主不能为空',
    }) 
    cntr_owner: number;

    /*spec_no: string;*/

    /* @IsDate({
        message: '箱制造时间错误'
    }) */
    cntr_date: Date;

    refmachine_brand: string;
    refmachine_model: string;
    /* @IsDate({
        message: '机组日期错误'
    }) */
    refmachine_date: Date;
    in_ship_nam: string;
    in_voyage: string;
    scale_wgt: number;
    free_days: number;
    in_reason: string;
    allow_date: Date;
    
    /* @IsArray()
    @ValidateNested({ each: true }) // 对数组中的每个元素应用验证
    @Type(() => gateinCntrFeedet) // 使用class-transformer确保类型安全    */
    feedet: gateinCntrFeedet[];
}
export class GateOutDto {
    @IsNumber(
        {},
        {
            message: '缺少id',
        },
    )
    id: number;
    
    @IsString({
        message: '放箱号错误'
    })
    @IsNotEmpty({
        message: '放箱号不能为空'
    })
    release_no: string;

    @IsNumber({}, {
        message: '客户cuowu '
    })
    @IsNotEmpty({
        message: '客户不能为空'
    })
    cntr_corp_cod: number;

    current_stat: string;
    leav_port_tim: Date;
    allow_date: Date;
    out_truck_sn: number;
    out_truck_no_c: string;
    out_truck_tel: string;
    remark: string;

}
export class ReplyCntrFixDto {
    @IsArray({
        message: 'ids参数类型错误',
    })
    @ArrayNotEmpty({
        message: 'ids参数不能为空',
    })
    @IsNumber(
        {},
        {
            each: true,
            message: 'ids参数类型错误',
        },
    )
    ids: number[];
    @IsNotEmpty({
        message: '批复内容不能为空'
    })
    msg: string;
    @IsNotEmpty({
        message: '批复类型不能为空'
    })
    reply_id: string;
}


/**
 * 根据计划导入箱、 计划增加预定箱号
 */
export class InplanImportCntrDto {
    @IsNotEmpty({
        message: '计划ID不能为空',
    })
    plan_id: number;

    @IsArray() // 确保数组中的每个元素都是字符串
    @IsNotEmpty() // 确保数组不为空
    @Type(() => String) // 使用class-transformer确保类型安全
    public cntrs!: string[];
}

/**
 * 查询计划预定箱号
 */
export class QueryPlanCntrsDto {
    @IsNotEmpty({
        message: '计划ID不能为空',
    })
    plan_id: number;
}

export class QueryCntrNoDto {
    @IsNotEmpty({
        message: '箱编号不能为空',
    })
    cntr_no: number;
}



export class CntrLeaseDto {
    @IsNumber({}, {
        message: '箱编号错误'
    })
    @IsNotEmpty({
        message: '箱编号不能为空',
    })
    cntr_no: number;

    @IsNumber({}, {
        message: '起租计划号错误'
    })
    @IsNotEmpty({
        message: '起租计划不能为空',
    })
    lease_sn: number;
    
    @IsNotEmpty({
        message: '起租场站不能为空'
    })
    out_cfs: number;
    @IsNotEmpty({
        message: '起租日期不能为空'
    })
    out_date: Date;
    out_truck_no_c: string;
    out_driver_tel: string;
  
    rent_sn: number;
    back_cfs: number;
    back_date: Date;

    back_truck_no_c: string;
    back_driver_tel: string;

}
export class CntrLeaseRateDto {

    @IsNumber({}, { each: true }) // 验证数组中的每个元素是否为数字 [[7]]
    @ArrayNotEmpty() // 确保数组不为空 [[8]]
    ids: number[];

    
    
    @IsNotEmpty({
        message: '租箱费率不能为空'
    })
    day_rate: number;

    @IsNotEmpty({
        message: '货币不能为空'
    })
    currency_cod: string;
}
export class ReleaseFormDto {
    @IsNotEmpty({
        message: '计划号不能为空'
    })
    plan_id: number;
    /* @IsNotEmpty({
        message: '放箱单号不能为空'
    }) */
    release_no: string;

    
    create_tim: Date;

    /* @IsNotEmpty({
        message: '箱尺寸不能为空'
    }) */
    cntr_siz_cod: string;
    /* @IsNotEmpty({
        message: '箱型不能为空'
    }) */
    cntr_typ_cod: string;

    /* @IsNotEmpty({
        message: '箱况不能为空'
    }) */
    dam_id: string;
    cfs_cod: number;
    cntr_corp_cod: number;
    @IsNotEmpty({
        message: '箱号信息不能为空'
    })
    cntr_info: string;

    @IsNotEmpty({
        message: '放箱单格式不能为空'
    })
    form_style: string;   // 珉钧  宁波

    @IsNotEmpty({
        message: '箱量不能为空'
    })
    cntr_num: number;

    oper_nam: string;
    filepath: string;
}

export class PortCntrStatDto {
    @IsNotEmpty({
        message: '箱编号不能为空'
    })
    cntr_no: number;

    @IsNotEmpty({
        message: '箱号不能为空'
    })
    cntr: string;

    @IsNotEmpty({
        message: '动态代码不能为空'
    })
    cntr_stat_cod: string;

    @IsNotEmpty({
        message: '动态时间不能为空'
    })
    stat_tim: Date;

    
    current_stat: string;
    dam_id: string;
    cfs_cod: number;
    plan_id: number;
    bill_no: string;
    truck_no: string;
    driver_tel: string;
    cal_stack: string;
}

export class DeletePortCntrStatDto {
    @IsNotEmpty({
        message: '动态ID不能为空'
    })
    id: number;

    @IsNotEmpty({
        message: '箱编号不能为空'
    })
    cntr_no: number;
}

export class DeletePortCntrStatsDto {
    @IsArray()
    @ValidateNested({ each: true }) // 对数组中的每个元素应用验证
    @Type(() => DeletePortCntrStatDto) // 使用class-transformer确保类型安全
    @IsOptional()
    cntrStats: DeletePortCntrStatDto[];
}